import QtQuick 2.14
import QtQuick.Window 2.14

Window {
    visible: true
    width: clockBackground.sourceSize.width
    height: clockBackground.sourceSize.height
    title: qsTr("Clock")
    Image {
        anchors.centerIn: parent
        id: clockBackground
        source: "resource/background.png"
    }

    property int interval: 1000

    Image {
        anchors.fill: parent
        id: secNeedle
        Image {
            anchors.centerIn: parent
            anchors.verticalCenterOffset: -40
            source: "resource/needle.png"
        }
        Behavior on rotation {
            NumberAnimation {
                duration: interval
            }
        }
    }

    Image {
        id: minNeedle
        anchors.fill: parent
        Image {
            anchors.centerIn: parent
            anchors.verticalCenterOffset: -48
            source: "resource/min.png"
        }
        Behavior on rotation {
            NumberAnimation {
                duration: interval
            }
        }
    }

    Image {
        id: hour
        anchors.fill: parent
        Image {
            anchors.centerIn: parent
            anchors.verticalCenterOffset: -32
            source: "resource/hour.png"
        }
        Behavior on rotation {
            NumberAnimation {
                duration: interval
            }
        }
    }

    Timer{
        id: timer
        interval: parent.interval
        repeat: true
        running: {
            let date = new Date
            secNeedle.rotation = date.getSeconds() * 6
            minNeedle.rotation = date.getMinutes() * 6 + date.getSeconds()*0.1;
            hour.rotation = date.getHours() * 30 + date.getMinutes() * 0.2 + date.getSeconds() * 1/120.0
        }

        onTriggered: {
            secNeedle.rotation += 6
            minNeedle.rotation += 0.1
            hour.rotation += 1/120.0;
        }
    }
}
